var app = getApp()
Page({
  /**
   * 页面的初始数据
   */
  data: {
    goodsList: [],
    openid: '',
    typeid: '',
    page:1,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    wx.showLoading({
      title: '正在加载...',
    })
    var that = this;
    wx.request({
      url: app.serverUrl + 'About/mall',
      // header: { 'content-type': 'application/x-www-form-urlencoded' },
      method: 'GET',
      dataType: 'json',
      data: {
        openid: app.openid,
        typeid: options.typeid,
        page: '1'
      },
      success: function(res) {
        that.setData({
          goodsList: res.data.data.list,
          typeid: options.typeid,
        });
        wx.hideLoading();
      }

    })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {
    wx.showNavigationBarLoading(); //在标题栏中显示加载
    var that = this;
    wx.request({
      url: app.serverUrl + 'About/mall',
      // header: { 'content-type': 'application/x-www-form-urlencoded' },
      method: 'GET',
      dataType: 'json',
      data: {
        openid: app.openid,
        typeid: that.data.typeid,
        page: '1'
      },
      success: function(res) {
        that.setData({
          goodsList: res.data.data.list
        })
      },
      complete: function() {
        // complete
        wx.hideNavigationBarLoading() //完成停止加载
        wx.stopPullDownRefresh() //停止下拉刷新
      }

    })
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function(options) {
    wx.showLoading({
      title: '正在加载...',
    })
    var that = this;
    that.setData({
      page:that.data.page+1
    })
    wx.request({
      url: app.serverUrl + 'About/mall',
      // header: { 'content-type': 'application/x-www-form-urlencoded' },
      method: 'GET',
      dataType: 'json',
      data: {
        openid: app.openid,
        typeid: that.data.typeid,
        page: that.data.page
      },
      success: function(res) {
        var arr=res.data.data.list;
        that.setData({
          goodsList: that.data.goodsList.concat(arr)
        });
        wx.hideLoading();
      }

    })
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  gofpdetail(e) {
    wx.navigateTo({
      url: '/pages/fpdetail/fpdetail?goodsid=' + e.currentTarget.dataset.goodsid,
    })
  },
})